let count: number = 0;
let roads:{[creepName:string]:any}={};

function repairRoad(sourceId: string): ICreepConfig {
    return {
        source: (creep: Creep) => {
            let spawn: Structure = Game.getObjectById<Structure>(sourceId);
            if (creep.withdraw(spawn, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) creep.moveTo(spawn)
        },
        // 建造
        target: (creep: Creep) => {
            if (count++ == 10) {
                roads[creep.name] = null;
                count = 0;
            }
            if (!roads[creep.name])
                roads[creep.name] = _.filter(Object.values(creep.room.find(FIND_STRUCTURES)),
                    structure => structure.structureType == STRUCTURE_ROAD);
            for (let i = 0; i < roads[creep.name].length; i++) {
                let road: AnyStructure = roads[creep.name][i];
                if (road.hitsMax - road.hits > 0) {
                    if (creep.repair(road) == ERR_NOT_IN_RANGE) creep.moveTo(road);
                    return
                }
            }
        },
        // 状态切换条件，稍后会给出具体实现
        switch: (creep: Creep) => creep.updateState()
    }
}

export {repairRoad, roads}